SHELL=bash 
include functions.make

all: instructions 

.PHONY: instructions run_project_from_start_to_finish wipe_all_project_outputs

# Run all code from start to finish
run_project_from_start_to_finish: docinc-run_project.do
	-rm $(basename $<).log
	qstata --dofile=$< --cpucount=8 --statatype=mp --memsize=200000
	$(call wait_for_batch, $<)


# Clean directories (run first for total re-run of the project)
wipe_all_project_outputs:
	@echo "Are you sure you want to delete all directories with clean data, outputs, and exhibits? Type 'Y' to continue."
	@read -p "Continue? [Y/n]: " confirm && [ "$$confirm" = "Y" ]
	-rm -rf ../data ../output ../intermediate_csv ../temp ../figures ../tables

# Aux
instructions: 
	@echo "Run 'make run_project_from_start_to_finish' to execute the entire project in one PBS batch job"
	@echo "To run individual do files, first execute the program 'define_paths_globals' within docinc-run_project.do"

delete_junk_files:
	-rm -rf logs twfe/geo_twfe/logs twfe/firm_twfe/logs
	-rm twfe/geo_twfe/*.txt twfe/firm_twfe/*.txt

# Readme (public-side recipe)
readme.pdf: readme.tex
	pdflatex -shell-escape -draftmode $< 
	pdflatex $<
	-rm readme.aux readme.auxlock readme.log readme.out